<?php
class Registration extends CI_Controller {


	
	public function __construct()
	{
		parent::__construct();
		$this->load->model('registration_model');
	}
	
	
	public function index()
	{
		// required
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->helper('recaptcha');
		
		// validation
		$this->form_validation->set_rules('first_name', 'First Name', 'required');
		$this->form_validation->set_rules('last_name', 'Last name', 'required');
		$this->form_validation->set_rules('gender', 'Gender', 'required');
		$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
		$this->form_validation->set_rules('phone', 'Phone', 'required');
		$this->form_validation->set_rules('address', 'Address', 'required');
		$this->form_validation->set_rules('city', 'City', 'required');
		$this->form_validation->set_rules('state', 'State', 'required');
		$this->form_validation->set_rules('zip_code', 'Zip Code', 'required');
		$this->form_validation->set_rules('terms', 'Terms and Conditions', 'required');
		$this->form_validation->set_rules('optin', 'Optin', 'trim'); //
		$this->form_validation->set_rules('recaptcha_challenge_field', 'reCAPTCHA', 'required|recaptcha_matches');  //'required|recaptcha_matches'
		//$this->form_validation->set_rules('message', 'Message', 'required');
		
		// custom messages
		//$this->form_validation->set_message('recaptcha_challenge_field', 'The reCAPTCHA entered is incorrect'); 
		
		// error output tags
		$this->form_validation->set_error_delimiters('<li>', '</li>');
		/*	
		hidden (promotion, facebook, vendor, date)
		*/

		//
		if ($this->form_validation->run() === FALSE)
		{
			// template
			$data['title'] = 'Registration';
			$this->load->view('templates/header', $data);
			$this->load->view('registration/index', $data);
			$this->load->view('templates/footer', $data);
		}
		else
		{
			// insert
			$this->registration_model->check();
			// view
			$data['title'] = 'Registration';
			$this->load->view('templates/header', $data);
			$this->load->view('registration/success');
			$this->load->view('templates/footer');
		}

	}
	


	/*
	public function register()
	{
		$this->load->helper('form');
		$this->load->library('form_validation');
	
		$data['title'] = 'Registration Page';
	
		$this->form_validation->set_rules('title', 'Title', 'required');
		$this->form_validation->set_rules('text', 'text', 'required');
	
		if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('templates/header', $data);
			$this->load->view('registration');
			$this->load->view('templates/footer');
	
		}
		else
		{
			$this->registration_model->set_news();
			$this->load->view('templates/header', $data);
			$this->load->view('registration/success');
			$this->load->view('templates/footer');
		}
	}
	*/

}